package com.ftwj.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class LoginInterceptor implements HandlerInterceptor {

    /**
     * 在请求被处理之前调用
     *
     * @param request
     * @param response
     * @param handler
     * @return
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest request, 
                             HttpServletResponse response,
                             Object handler) throws Exception {
        String url = request.getRequestURI().trim();



        //String ipAddress = IpUtil.getIpAddr(request);
        //if (ipAddress.contains("127.0.0.1") ||
        //        ipAddress.contains("192.168.9") ||
        //        ipAddress.contains("125.74") ||
        //        ipAddress.contains("125.75") ||
        //        ipAddress.contains("10.42") ||
        //        ipAddress.contains("10.43") ||
        //        ipAddress.contains("61.178.85")) {
        //    return true;
        //}
        //System.out.println("ip地址：" + ipAddress);
        return true;
    }

    /**
     * 在请求被处理后，视图渲染之前调用
     *
     * @param request
     * @param response
     * @param handler
     * @param modelAndView
     * @throws Exception
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    /**
     * 在整个请求结束后调用
     *
     * @param request
     * @param response
     * @param handler
     * @param ex
     * @throws Exception
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {


    }
}
